<?php
/**
 * <https://y.st./>
 * Copyright © 2017 Alex Yst <mailto:copyright@y.st>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org./licenses/>.
**/

$xhtml = array(
	'title' => 'Unit5.java',
	'subtitle' => 'Written in <span title="Programming 1">CS 1102</span> of <a href="http://www.uopeople.edu/">University of the People</a>, finalised on 2017-05-10',
	'copyright year' => '2017',
	'body' => <<<END
<h2>Source code:</h2>
<blockquote>
<pre><code>/*
 * Copyright (C) 2017 Alex Yst
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
 */
package unit5;

/**
 * Alex Yst&apos;s CS 1102 (Programming 1) Unit 5 submission
 * 
 * This class was programmed to fill the requirements on the Unit 5 programming
 * assignment in University of the People&apos;s CS 1102 (Programming 1) course.
 * 
 * @author Alex Yst
 */
public class Unit5 {
/**
 * This method defines a class used for stats calculation, then uses it to
 * compute some statistics.
 * 
 * @param arguments This parameter is unused.
 */
	public static void main(String[] arguments) {
/*
 * An object of class StatCalc can be used to compute several simple statistics
 * for a set of numbers.  Numbers are entered into the dataset using
 * the enter(double) method.  Methods are provided to return the following
 * statistics for the set of numbers that have been entered: The number
 * of items, the sum of the items, the average, and the standard deviation
 */

		class StatCalc {

			private int count;   // Number of numbers that have been entered.
			private double sum;  // The sum of all the items that have been entered.
			private double squareSum;  // The sum of the squares of all the items.

/**
 * Add a number to the dataset.  The statistics will be computed for all
 * the numbers that have been added to the dataset using this method.
 */
			public void enter(double num) {
				count++;
				sum += num;
				squareSum += num*num;
			}

/**
 * Return the number of items that have been entered into the dataset.
 */
			public int getCount() {
				return count;
			}

/**
 * Return the sum of all the numbers that have been entered.
 */
			public double getSum() {
				return sum;
			}

/**
 * Return the average of all the items that have been entered.
 * The return value is Double.NaN if no numbers have been entered.
 */
			public double getMean() {
				return sum / count;
			}

/**
 * Return the standard deviation of all the items that have been entered.
 * The return value is Double.NaN if no numbers have been entered.
 */
			public double getStandardDeviation() {
				double mean = getMean();
				return Math.sqrt( squareSum/count - mean*mean );
			}
		}  // end class StatCalc

		StatCalc myStatCalc = new StatCalc();
		myStatCalc.enter(5);
		myStatCalc.enter(7);
		myStatCalc.enter(12);
		myStatCalc.enter(23);
		myStatCalc.enter(3);
		myStatCalc.enter(2);
		myStatCalc.enter(8);
		myStatCalc.enter(14);
		myStatCalc.enter(10);
		myStatCalc.enter(5);
		myStatCalc.enter(9);
		myStatCalc.enter(13);
		System.out.println(&quot;The following number set has the following statistics.&quot;);
		System.out.println(&quot;Number Set:         5, 7, 12, 23, 3, 2, 8, 14, 10, 5, 9, 13&quot;);
		System.out.println(&quot;Count:              &quot; + myStatCalc.getCount());
		System.out.println(&quot;Mean:               &quot; + myStatCalc.getMean());
		System.out.println(&quot;Standard Deviation: &quot; + myStatCalc.getStandardDeviation());
	}
}</code></pre>
</blockquote>
<h2>Output:</h2>
<blockquote>
<pre>run:
The following number set has the following statistics.
Number Set:         5, 7, 12, 23, 3, 2, 8, 14, 10, 5, 9, 13
Count:              12
Mean:               9.25
Standard Deviation: 5.539629951540085
BUILD SUCCESSFUL (total time: 0 seconds)</pre>
</blockquote>
END
);
